<template>
    <div class="app-container">
        <br>
        <br>
        <br>
        <div class="contentB">
            <div class="inside">
                <el-row :gutter="5">
                    <el-col :span="12" ref="leftView">
                        <div>
                            <el-form :model="form" :rules="rules" ref="form" label-width="200px" class="demo-ruleForm">
                                <el-form-item label="系统名称" prop="name">
                                    <el-input style="width: 400px"
                                              v-model.trim="form.name"
                                              placeholder="请输入用户姓名"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item>
                                    <div style="margin-top:20px;margin-left: 15%;">
                                        <el-row>
                                            <el-button type="primary" @click="infoSubmit" round>
                                                保存
                                            </el-button>
                                        </el-row>
                                    </div>
                                </el-form-item>
                            </el-form>
                        </div>

                    </el-col>
                </el-row>
            </div>
        </div>
    </div>
</template>

<script>
    import {queryPlatConfigItemInfo, updatePlatConfigItemInfo} from '../../api/platConfigItem'
    export default {
        name: 'add',
        data(){
            return{
                form :{
                    name: '',
                },
                rules: {
                    name: [
                        { required: true, message: '请输入系统名称', trigger: 'blur' }
                    ],
                },
            }
        },
        methods:{
            infoSubmit(){
                this.$refs['form'].validate((valid) => {
                    if (valid) {
                         this.updateInfo()
                    }
                })
            },

            updateInfo(){//修改
                let param = {
                    configName : 'SYSTEM_NAME',
                    configVal : this.form.name
                }
                const loading = this.$loading(this.Global.loadingOption);
                updatePlatConfigItemInfo(param).then(() => {
                    loading.close()
                    this.$notify({
                        title: '成功',
                        message: '修改成功',
                        type: 'success',
                        duration: 2000
                    })
                    this.getInfo()
                }).catch(error => {
                    loading.close()
                    console.log(error)
                })
            },

            getInfo(){//查详情
                let param  = {
                    configName : 'SYSTEM_NAME',
                }
                const loading = this.$loading(this.Global.loadingOption);
                queryPlatConfigItemInfo(param).then(response => {
                    loading.close()
                    if(response.data.data){
                        this.form.name = response.data.data.configVal
                    }
                }).catch(error=>{
                    loading.close()
                    console.log(error)
                })
            },
        },

        created () {
            this.getInfo()
        }
    }
</script>

<style scoped lang="scss">

</style>
